package st.business.tepth.business.history.detail;

import android.view.View;

import com.chad.library.adapter.base.BaseMultiItemQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chad.library.adapter.base.entity.MultiItemEntity;

import java.util.List;

import st.business.tepth.R;
import st.business.tepth.business.history.detail.entity.Lv_1;
import st.business.tepth.business.history.detail.entity.Lv_2;
import st.business.tepth.business.history.detail.entity.Lv_2_1;
import st.business.tepth.business.history.detail.entity.Lv_2_1_1;
import st.business.tepth.business.history.detail.entity.Lv_3;
import st.business.tepth.business.history.detail.entity.Lv_3_1;
import st.business.tepth.business.history.detail.entity.Lv_3_2;
import st.business.tepth.business.history.detail.entity.Lv_4;
import st.business.tepth.business.history.detail.entity.Lv_5;
import st.business.tepth.business.history.detail.entity.Lv_5_1;

/**
 * @author zhangyu
 * @date 2019/3/4
 */
public class HistoryDetailAdapter extends BaseMultiItemQuickAdapter<MultiItemEntity,
        BaseViewHolder> {
    public static final int TYPE_1 = 1;
    public static final int TYPE_2 = 2;
    public static final int TYPE_2_1 = 3;
    public static final int TYPE_2_1_1 = 4;
    public static final int TYPE_3 = 5;
    public static final int TYPE_3_1 = 6;
    public static final int TYPE_3_2 = 7;
    public static final int TYPE_4 = 8;
    public static final int TYPE_5 = 9;
    public static final int TYPE_5_1 = 10;

    /**
     * Same as QuickAdapter#QuickAdapter(Context,int) but with
     * some initialization data.
     *
     * @param data A new list is created out of this one to avoid mutable list
     */
    public HistoryDetailAdapter(List<MultiItemEntity> data) {
        super(data);
        addItemType(TYPE_1, R.layout.item_history_detail_type1);
        addItemType(TYPE_2, R.layout.item_history_detail_type2);
        addItemType(TYPE_2_1, R.layout.item_history_detail_type2_1);
        addItemType(TYPE_2_1_1, R.layout.item_history_detail_type2_1_1);
        addItemType(TYPE_3, R.layout.item_history_detail_type2);
        addItemType(TYPE_3_1, R.layout.item_history_detail_type3_1);
        addItemType(TYPE_3_2, R.layout.item_history_detail_type3_2);
        addItemType(TYPE_4, R.layout.item_history_detail_type4);
        addItemType(TYPE_5, R.layout.item_history_detail_type5);
        addItemType(TYPE_5_1, R.layout.item_history_detail_type5_1);
    }


    @Override
    protected void convert(final BaseViewHolder helper, MultiItemEntity item) {
        switch (item.getItemType()) {
            case TYPE_1:
                final Lv_1 lv_1 = (Lv_1) item;
                helper.setText(R.id.tv_classification, lv_1.getName());
                helper.getView(R.id.tv_classification).setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        int pos = helper.getAdapterPosition();
                        if (lv_1.isExpanded()) {
                            collapse(pos);
                        } else {
                            expand(pos);
                        }
                    }
                });
                break;
            case TYPE_2:
                Lv_2 lv_2 = (Lv_2) item;
                helper.setText(R.id.tv_name, lv_2.getName());
                helper.setText(R.id.tv_date, lv_2.getDate());
                break;
            case TYPE_2_1:
                Lv_2_1 lv_2_1 = (Lv_2_1) item;
                helper.setText(R.id.tv_content, lv_2_1.getRepair() + "/"
                        + lv_2_1.getDiagnose());
                break;
            case TYPE_2_1_1:
                Lv_2_1_1 lv_2_1_1 = (Lv_2_1_1) item;
                helper.setText(R.id.tv_program, lv_2_1_1.getProgram());
                helper.setText(R.id.tv_person, lv_2_1_1.getPersons());
                helper.setVisible(R.id.iv_contact,
                        lv_2_1_1.getAssociationStatus() == 1);
                break;
            case TYPE_3:
                Lv_3 lv_3 = (Lv_3) item;
                helper.setText(R.id.tv_name, lv_3.getName());
                helper.setText(R.id.tv_date, lv_3.getDate());
                break;
            case TYPE_3_1:
                Lv_3_1 lv_3_1 = (Lv_3_1) item;
                helper.setText(R.id.tv_standard_work_content, lv_3_1.getStandard());
                helper.setText(R.id.tv_person, lv_3_1.getPersons());
                break;
            case TYPE_3_2:
                Lv_3_2 lv_3_2 = (Lv_3_2) item;
                helper.setText(R.id.tv_diagnose, lv_3_2.getDiagnose());
                break;
            case TYPE_4:
                Lv_4 lv_4 = (Lv_4) item;
                helper.setText(R.id.tv_name, lv_4.getName());
                helper.setText(R.id.tv_date, lv_4.getDate());
                helper.setText(R.id.tv_check_pass,
                        lv_4.getConclusion() + "      " + lv_4.getPersons());
                break;
            case TYPE_5:
                Lv_5 lv_5 = (Lv_5) item;
                helper.setText(R.id.tv_name, lv_5.getName());
                break;
            case TYPE_5_1:
                Lv_5_1 lv_5_1 = (Lv_5_1) item;
                helper.setText(R.id.tv_check_pass, lv_5_1.getClassification());
                helper.setText(R.id.tv_content, lv_5_1.getStandard());
                break;
        }
    }

}
